﻿using System;
using System.IO;
using System.Windows.Forms;
using UpdateHelper;

namespace HousekeepingSystem
{
    public partial class mainForm : Form
    {
        public mainForm()
        {
            InitializeComponent();
            DefaultInfo();
        }

        private void mainForm_Load(object sender, EventArgs e)
        {
            UpdateCheck.Start();
        }

        private void DefaultInfo()
        {
            if (!Directory.Exists(Application.StartupPath + @"\info"))
            {
                Directory.CreateDirectory(Application.StartupPath + @"\info");
            }
            if (!File.Exists(Application.StartupPath + @"\info\ContractTable.json"))
            {
                byte[] ContractTable = Properties.Resources.ContractTable;
                FileStream fsObj = new FileStream(Application.StartupPath + @"\info\ContractTable.json", FileMode.CreateNew);
                fsObj.Write(ContractTable, 0, ContractTable.Length);
                fsObj.Close();
            }
            if (!File.Exists(Application.StartupPath + @"\info\DispatchTable.json"))
            {
                byte[] DispatchTable = Properties.Resources.DispatchTable;
                FileStream fsObj = new FileStream(Application.StartupPath + @"\info\DispatchTable.json", FileMode.CreateNew);
                fsObj.Write(DispatchTable, 0, DispatchTable.Length);
                fsObj.Close();
            }
            if (!File.Exists(Application.StartupPath + @"\info\EmployeeList.json"))
            {
                byte[] EmployeeList = Properties.Resources.EmployeeList;
                FileStream fsObj = new FileStream(Application.StartupPath + @"\info\EmployeeList.json", FileMode.CreateNew);
                fsObj.Write(EmployeeList, 0, EmployeeList.Length);
                fsObj.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            panel1.Focus();
            new Form1().ShowDialog();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            panel1.Focus();
            new Form2().ShowDialog();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            panel1.Focus();
            new Form3().ShowDialog();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            panel1.Focus();
            new Form4().ShowDialog();
        }

        private void mainForm_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Escape)
            {
                var result = MessageBox.Show(this, "是否要退出程序?", "提示", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    Application.Exit();
                }
                e.Handled = true;
            }
        }
    }
}
